// -------------------------------------------------------------
// api: report.resourceCount
// time: 2020-07-21
// author: minner
// -------------------------------------------------------------
exports['report.resourceCount'] = obj_api = {
    '1.0': function (args, session, callback) {
        if (!session.account_id) {
            return callback(12, null, '会话已失效');
        }

        // 查询各资源数量
        let sql_select = '\
SELECT \
(SELECT COUNT(*) FROM deploy_respool) count_respool,\
(SELECT COUNT(*) FROM deploy_respool_area) count_respool_area,\
(SELECT COUNT(*) FROM deploy_project) count_project,\
(SELECT COUNT(*) FROM deploy_project_app) count_project_app,\
(SELECT GROUP_CONCAT( server_type, "-", server_count) FROM (\
   SELECT server_type,COUNT(*) server_count FROM `deploy_respool_area_server`\
    WHERE STATUS IN(1,2) GROUP BY server_type) t) count_server';
        uim.db_query(sql_select, function (err, results, fields) {
            if (err) {
                return callback(1, null, '查询数量时出错：' + err)
            }
            callback(0, { resource_counts: results[0] });
        });
    },
};
